from selenium.webdriver.common.by import By

from teacher.ecshop.base.base import Base
from teacher.ecshop.utils.Logger import Logger

logger = Logger('GoodsListPage').getlog()


class GoodsListPage(Base):
    def __init__(self, driver):
        Base.__init__(self, driver)

    def into_menu_frame(self):
        self.into_frame('menu-frame')
        logger.info('进入到menu-frame帧')

    def click_goods_link(self):
        self.click((By.LINK_TEXT, '商品列表'))
        logger.info('点击商品列表链接')

    def out_menu_frame(self):
        self.out_frame()
        logger.info('退出menu-frame帧')

    def into_main_frame(self):
        self.into_frame('main-frame')
        logger.info('进入main-frame帧')

    def input_keyword(self):
        self.input((By.NAME, 'keyword'), 'N85')
        logger.info('在搜索框输入N85')

    def click_search_button(self):
        self.click((By.XPATH, '//input[@value=" 搜索 "]'))
        logger.info('点击搜索')

    def select_by_type(self):
        self.select_by_text((By.NAME, 'intro_type'), '新品')
        logger.info('在下拉列表中选择新品')

    def input_goods_name(self):
        self.input((By.NAME, 'goods_name'), 'DiorN85999')
        logger.info('输入商品名称：DiorN85999')

    def select_category(self):
        self.select_by_text((By.NAME, 'cat_id'), '奥特曼')
        logger.info('在下商品类型中选择奥特曼')

    def click_submit(self):
        self.click((By.XPATH, '//input[@value=" 确定 "]'))
        logger.info('点击确定')

    def click_add_goods_link(self):
        self.click((By.LINK_TEXT, '添加新商品'))
        logger.info('点击添加新商品链接')

    def click_is_not_sales(self):
        self.click((By.XPATH, '//img[@src="images/yes.gif"]'))
        logger.info('点击下架')

    def get_search_count(self):
        data = self.get_text((By.XPATH, '//*[@id="totalRecords"]'))
        return data
